﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProcessParameter" :model="stateProcessParameter.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RouteId_FormItem" prop="Entity.RouteId" :label="$t('message.autotrans._Model_ProcessParameter_Route')">
            <el-select v-model="stateProcessParameter.vmModel.Entity.RouteId" clearable>
               <el-option v-for="item in stateProcessParameter.AllRoutes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpId_FormItem" prop="Entity.OpId" :label="$t('message.autotrans._Model_ProcessParameter_Op')">
            <el-select v-model="stateProcessParameter.vmModel.Entity.OpId" clearable>
               <el-option v-for="item in stateProcessParameter.AllOps" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagId_FormItem" prop="Entity.TagId" :label="$t('message.autotrans._Model_ProcessParameter_TagId')">
            <el-input v-model="stateProcessParameter.vmModel.Entity.TagId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagName_FormItem" prop="Entity.TagName" :label="$t('message.autotrans._Model_ProcessParameter_TagName')">
            <el-input v-model="stateProcessParameter.vmModel.Entity.TagName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_SetValue_FormItem" prop="Entity.SetValue" :label="$t('message.autotrans._Model_ProcessParameter_SetValue')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessParameter_SetValue')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessParameter.vmModel.Entity.SetValue" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Precision_FormItem" prop="Entity.Precision" :label="$t('message.autotrans._Model_ProcessParameter_Precision')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessParameter_Precision')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessParameter.vmModel.Entity.Precision" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ParameterName_FormItem" prop="Entity.ParameterName" :label="$t('message.autotrans._Model_ProcessParameter_ParameterName')">
            <el-input v-model="stateProcessParameter.vmModel.Entity.ParameterName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DataType_FormItem" prop="Entity.DataType" :label="$t('message.autotrans._Model_ProcessParameter_DataType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessParameter_DataType')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessParameter.vmModel.Entity.DataType" clearable>
               <el-option key="Sys_Bit" value="Sys_Bit" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Bit')"></el-option>
               <el-option key="Sys_Byte" value="Sys_Byte" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Byte')"></el-option>
               <el-option key="Sys_Word" value="Sys_Word" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Word')"></el-option>
               <el-option key="Sys_DWork" value="Sys_DWork" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DWork')"></el-option>
               <el-option key="Sys_Int" value="Sys_Int" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Int')"></el-option>
               <el-option key="Sys_DInt" value="Sys_DInt" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DInt')"></el-option>
               <el-option key="Sys_Real" value="Sys_Real" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Real')"></el-option>
               <el-option key="Sys_LReal" value="Sys_LReal" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_LReal')"></el-option>
               <el-option key="Sys_String" value="Sys_String" :label="$t('message.autotrans._Enum_TagDataTypeEnum_Sys_String')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_ProcessParameter_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessParameter_Active')}), trigger: 'blur' }]" >
            <el-switch v-model="stateProcessParameter.vmModel.Entity.Active" clearable></el-switch>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitProcessParameter"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseProcessParameter"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProcessManagementProcessParameterEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { processparameterApi } from '/@/api/processmanagement/processparameter';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProcessParameter = ref();
const stateProcessParameter = reactive({
    vmModel: {
	  Entity:{
        RouteId: null,
        OpId: null,
        TagId: null,
        TagName: '',
        SetValue: '',
        Precision: null,
        ParameterName: '',
        DataType: undefined,
        Active: undefined,
        ID:null,
      },

	},
    
    AllRoutes: [] as any[],
    AllOps: [] as any[],
});

// 取消
const onCloseProcessParameter = () => {
    closeDialog();
};

// 提交
const onSubmitProcessParameter = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProcessParameter.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            processparameterApi().edit(stateProcessParameter.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/ProcessManagement/ProcessParameter/GetProcessRoutes',[],false).then(x=>{stateProcessParameter.AllRoutes = x});
    other.getSelectList('/api/ProcessManagement/ProcessParameter/GetProcessRouteItems',[],false).then(x=>{stateProcessParameter.AllOps = x});
    if (ci.attrs["wtmdata"]) {
		stateProcessParameter.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProcessParameter.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	processparameterApi().get(stateProcessParameter.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProcessParameter.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

